<!DOCTYPE html>
<!--
/*******************************************************************************
#      ____               __          __  _      _____ _       _               #
#     / __ \              \ \        / / | |    / ____| |     | |              #
#    | |  | |_ __   ___ _ __ \  /\  / /__| |__ | |  __| | ___ | |__   ___      #
#    | |  | | '_ \ / _ \ '_ \ \/  \/ / _ \ '_ \| | |_ | |/ _ \| '_ \ / _ \     #
#    | |__| | |_) |  __/ | | \  /\  /  __/ |_) | |__| | | (_) | |_) |  __/     #
#     \____/| .__/ \___|_| |_|\/  \/ \___|_.__/ \_____|_|\___/|_.__/ \___|     #
#           | |                                                                #
#           |_|                 _____ _____  _  __                             #
#                              / ____|  __ \| |/ /                             #
#                             | (___ | |  | | ' /                              #
#                              \___ \| |  | |  <                               #
#                              ____) | |__| | . \                              #
#                             |_____/|_____/|_|\_\                             #
#                                                                              #
#                              (c) 2010-2011 by                                #
#           University of Applied Sciences Northwestern Switzerland            #
#                     Institute of Geomatics Engineering                       #
#                           martin.christen@fhnw.ch                            #
********************************************************************************
*     Licensed under MIT License. Read the file LICENSE for more information   *
*******************************************************************************/

                      TUTORIAL 4.4: Visibility distance
                      
*******************************************************************************/
-->
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="../../../external/closure-library/closure/goog/base.js"></script>
<script type="text/javascript" src="../../../compiled/deps.js"></script>
<script type="text/javascript">goog.require('owg.OpenWebGlobe');</script>

<script type="text/javascript">

var poilayer;
var hidden = false;

//------------------------------------------------------------------------------
// Render-Event: called every frame:
function OnRender(context)
{  
   ogSetTextColor(context, 0,1,0);
   ogDrawText(context, "Click middle mouse button to add a POI", 0, 50);
   ogDrawText(context, "Visibility range is set to 10-100km ", 0, 20);
}
//------------------------------------------------------------------------------
// Mouse-Down-Event: Called when a mouse button is pressed
function OnMouseDown(context, button, mx, my)
{
   // retrieve the scene attached to context:
   var scene = ogGetScene(context);
   
   // get poi id of picked poi, returns -1 if no poi picked. 
   var pickedPoiId = ogPickPOI(scene,mx,my);
   if(pickedPoiId > 0)
   {
      // change poi icon
      ogChangePOIIcon(pickedPoiId,"http://www.openwebglobe.org/data/media/airport.png");
   }
   
   // call the pickglobe function, this gives the result in lng, lat, elv
   var result = ogPickGlobe(scene, mx, my);
   if (button == 1 && result[0])
   {
      // place poi:
      var NewPoiDefinition = 
      {
         icon     : "http://www.openwebglobe.org/data/media/cycling.png",
         position :  [result[1], result[2], result[3]+2000],
         size 		: 	50,
         visibilityRange : [10,100] //visibility range in km!
      };

      var poi = ogCreatePOI(poilayer,NewPoiDefinition);
   }
}
//------------------------------------------------------------------------------
function OnKeyDown(ctx,key)
{
   if(!hidden && key == 49)
   {
      hidden = true;
      ogHidePOILayer(poilayer);
   }
   else
   {
      hidden = false;
      ogShowPOILayer(poilayer);
   }
}
//------------------------------------------------------------------------------
function main()
{
   // (0) Set location of Artwork directory. Because of CORS this can't be local
   // if you want to open this using file://...
   ogSetArtworkDirectory("http://www.openwebglobe.org/art/");
   
   // (1) create an OpenWebGlobe context using canvas
   // first parameter is canvas-id and second is "fullscreen"
   var ctx = ogCreateContextFromCanvas("canvas", true);
   
   // (2) Create a virtual globe
   var globe = ogCreateGlobe(ctx);
   
   // (3) Add an image and an elevation layer
   var imgBlueMarble500 = 
   {
      url     : ["http://www.openwebglobe.org/data/img"],
      layer   : "World500",
      service : "i3d"
   };
   
   var elvSRTM_CH = 
   {
      url     : ["http://www.openwebglobe.org/data/elv"],
      layer   : "SRTM",
      service : "i3d"
   };
   
   ogAddImageLayer(globe, imgBlueMarble500);
   ogAddElevationLayer(globe, elvSRTM_CH);
   

   // (4) Set the "Render-Callback" function.
   // The callback function will be called everytime a frame is drawn.
   ogSetRenderFunction(ctx, OnRender);
   
   // (5) Set the mouse down function. We need this for picking!
   ogSetMouseDownFunction(ctx, OnMouseDown);
   
   // (5) Set the mouse down function. We need this for picking!
   ogSetKeyDownFunction(ctx, OnKeyDown);
   
   // (6) Set the background color
   ogSetBackgroundColor(ctx, 0.2,0.2,0.7,1);
   
   // (7) Define a POI Layer, POIs will be created in "OnMouseDown"-Callback function
   // first, we need to retrieve the scene:
   var scene = ogGetScene(ctx);   
   var world = ogGetWorld(scene);
   poilayer = ogCreatePOILayer(world,"bicycle");
           
}
//------------------------------------------------------------------------------
</script>
</head>
<body onload="main()" style="padding:0px; margin:0px; overflow:hidden;">
   <div style="text-align: center">
   <canvas id="canvas"></canvas>          
   </div>
</body>
</html>
